﻿using Models.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace yymbDAL
{
    public class MySetService
    {
        /// <summary>
        /// 显示基本信息表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Information ShowInfo(int id)
        {
            using (yymbDBEntities db = new yymbDBEntities())
            {
                return db.Information.Where(n => n.UserID == id).SingleOrDefault();
            }
        }
        /// <summary>
        /// 修改基本信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public int SetInfo(Information info)
        {
            using (yymbDBEntities db = new yymbDBEntities())
            {
                db.Entry(info).State = System.Data.Entity.EntityState.Modified;
                return db.SaveChanges();
            }
        }
        /// <summary>
        /// 显示旧密码
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public string ShowPwd(int id)
        {
            using (yymbDBEntities db = new yymbDBEntities())
            {
                User user = db.User.Where(n => n.UserID == id).SingleOrDefault();
                string pwd = user.Password;
                return pwd;
            }
        }
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public int SetPwd(User user)
        {
            using (yymbDBEntities db = new yymbDBEntities())
            {
                db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                return db.SaveChanges();
            }
        }
        /// <summary>
        /// 显示教育信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Education ShowEduc(int id)
        {
            using (yymbDBEntities db = new yymbDBEntities())
            {
                return db.Education.Where(n => n.UserID == id).SingleOrDefault();
            }
        }
        /// <summary>
        /// 修改教育信息
        /// </summary>
        /// <param name="educ"></param>
        /// <returns></returns>
        public int SetEduc(Education educ)
        {
            using (yymbDBEntities db = new yymbDBEntities())
            {
                db.Entry(educ).State = System.Data.Entity.EntityState.Modified;
                return db.SaveChanges();
            }
        }
        /// <summary>
        /// 显示教育信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Occupation ShowOccupa(int id)
        {
            using (yymbDBEntities db = new yymbDBEntities())
            {
                return db.Occupation.Where(n => n.UserID == id).SingleOrDefault();
            }
        }
        /// <summary>
        /// 修改教育信息
        /// </summary>
        /// <param name="occupa"></param>
        /// <returns></returns>
        public int SetOccupa(Occupation occupa)
        {
            using (yymbDBEntities db = new yymbDBEntities())
            {
                db.Entry(occupa).State = System.Data.Entity.EntityState.Modified;
                return db.SaveChanges();
            }
        }
    }
}
